#include<iostream>
#include<stack>
using namespace std;
char a[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
int main(){
	int n,r;
	cin>>n>>r;
	if(n==0)cout<<0;
	if(n<0){
		cout<<"-";
		n=-n;
	}
	stack<char>s;
	while(n){
		s.push(a[n%r]);
		n/=r;
	}
	while(!s.empty()){
		cout<<s.top();
		s.pop();
	}
	return 0;
}